package com.haois.mp.database.interceptor.configuration;

import com.haois.mp.wechat.util.WxOAuth2AccessTokenUtil;
import com.haois.mp.database.interceptor.MpDataInterceptor;
import com.haois.mp.database.interceptor.MpInterceptor;
import com.haois.mp.database.module.remote.service.IGroupService;
import com.haois.mp.database.module.remote.service.IUserService;
import com.haois.mp.database.module.common.service.IUserTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by RuiHaoZ on 2017/11/25.
 */
@Configuration
public class MpInterceptorConfiguration extends WebMvcConfigurerAdapter {

    @Autowired
    private IUserTokenService iUserTokenService;
    @Autowired
    private WxOAuth2AccessTokenUtil wxOAuth2AccessTokenUtil;
    @Autowired
    private IUserService iUserService;
    @Autowired
    private IGroupService iGroupService;

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(
                new MpInterceptor(iUserTokenService, wxOAuth2AccessTokenUtil))
                .addPathPatterns("/wxmp/**")
//                .excludePathPatterns("/wxmp/remind/**")
//                .excludePathPatterns("/wxmp/rest/remind/**")
                .excludePathPatterns("/wxmp/driver/wz/info")
                .excludePathPatterns("/wxmp/rest/driver/wz/info/**")
                .excludePathPatterns("/wxmp/rest/user/login")
                .excludePathPatterns("/wxmp/user/register")
                .excludePathPatterns("/wxmp/user/login")

                .excludePathPatterns("/wxmp/yellow/toFollowList")
                .excludePathPatterns("/wxmp/rest/yellow/getAllOrg")
                .excludePathPatterns("/wxmp/user/hisInfo")

                .excludePathPatterns("/wxmp/user/toResetPSWPage")
                .excludePathPatterns("/wxmp/user/toRegisterPage")
                .excludePathPatterns("/wxmp/rest/user/register")
                .excludePathPatterns("/wxmp/info/noGroup")
                .excludePathPatterns("/wxmp/rest/sys/parameter")
                .excludePathPatterns("/wxmp/rest/user/sendCode")

                .excludePathPatterns("/wxmp/info/miniProgram")
                .excludePathPatterns("/wxmp/info/wechat")
                .excludePathPatterns("/wxmp/info/tempMsg")
                .excludePathPatterns("/wxmp/share/**")
                .excludePathPatterns("/wxmp/rest/share/**")
                .excludePathPatterns("/wxmp/rest/invite/**");


        registry.addInterceptor(
                new MpDataInterceptor(iUserService, iGroupService))
                .addPathPatterns("/wxmp/user/info")
                .addPathPatterns("/wxmp/group/group")
                .addPathPatterns("/wxmp/group/notice");

    }
}
